﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;

namespace AbpCompanyName.AbpProjectName.Migrations;

public partial class Upgraded_To_Abp_v340 : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.AlterColumn<string>(
            name: "ClaimType",
            table: "AbpUserClaims",
            maxLength: 256,
            nullable: true,
            oldClrType: typeof(string),
            oldNullable: true);

        migrationBuilder.AlterColumn<string>(
            name: "UserName",
            table: "AbpUserAccounts",
            maxLength: 32,
            nullable: true,
            oldClrType: typeof(string),
            oldNullable: true);

        migrationBuilder.AlterColumn<string>(
            name: "EmailAddress",
            table: "AbpUserAccounts",
            maxLength: 256,
            nullable: true,
            oldClrType: typeof(string),
            oldNullable: true);

        migrationBuilder.AlterColumn<string>(
            name: "ClaimType",
            table: "AbpRoleClaims",
            maxLength: 256,
            nullable: true,
            oldClrType: typeof(string),
            oldNullable: true);

        migrationBuilder.CreateTable(
            name: "AbpEntityChangeSets",
            columns: table => new
            {
                Id = table.Column<long>(nullable: false)
                    .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                BrowserInfo = table.Column<string>(maxLength: 256, nullable: true),
                ClientIpAddress = table.Column<string>(maxLength: 64, nullable: true),
                ClientName = table.Column<string>(maxLength: 128, nullable: true),
                CreationTime = table.Column<DateTime>(nullable: false),
                ExtensionData = table.Column<string>(nullable: true),
                ImpersonatorTenantId = table.Column<int>(nullable: true),
                ImpersonatorUserId = table.Column<long>(nullable: true),
                Reason = table.Column<string>(maxLength: 256, nullable: true),
                TenantId = table.Column<int>(nullable: true),
                UserId = table.Column<long>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpEntityChangeSets", x => x.Id);
            });

        migrationBuilder.CreateTable(
            name: "AbpEntityChanges",
            columns: table => new
            {
                Id = table.Column<long>(nullable: false)
                    .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                ChangeTime = table.Column<DateTime>(nullable: false),
                ChangeType = table.Column<byte>(nullable: false),
                EntityChangeSetId = table.Column<long>(nullable: false),
                EntityId = table.Column<string>(maxLength: 48, nullable: true),
                EntityTypeFullName = table.Column<string>(maxLength: 192, nullable: true),
                TenantId = table.Column<int>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpEntityChanges", x => x.Id);
                table.ForeignKey(
                    name: "FK_AbpEntityChanges_AbpEntityChangeSets_EntityChangeSetId",
                    column: x => x.EntityChangeSetId,
                    principalTable: "AbpEntityChangeSets",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateTable(
            name: "AbpEntityPropertyChanges",
            columns: table => new
            {
                Id = table.Column<long>(nullable: false)
                    .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                EntityChangeId = table.Column<long>(nullable: false),
                NewValue = table.Column<string>(maxLength: 512, nullable: true),
                OriginalValue = table.Column<string>(maxLength: 512, nullable: true),
                PropertyName = table.Column<string>(maxLength: 96, nullable: true),
                PropertyTypeFullName = table.Column<string>(maxLength: 192, nullable: true),
                TenantId = table.Column<int>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpEntityPropertyChanges", x => x.Id);
                table.ForeignKey(
                    name: "FK_AbpEntityPropertyChanges_AbpEntityChanges_EntityChangeId",
                    column: x => x.EntityChangeId,
                    principalTable: "AbpEntityChanges",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityChanges_EntityChangeSetId",
            table: "AbpEntityChanges",
            column: "EntityChangeSetId");

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityChanges_EntityTypeFullName_EntityId",
            table: "AbpEntityChanges",
            columns: new[] { "EntityTypeFullName", "EntityId" });

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityChangeSets_TenantId_CreationTime",
            table: "AbpEntityChangeSets",
            columns: new[] { "TenantId", "CreationTime" });

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityChangeSets_TenantId_Reason",
            table: "AbpEntityChangeSets",
            columns: new[] { "TenantId", "Reason" });

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityChangeSets_TenantId_UserId",
            table: "AbpEntityChangeSets",
            columns: new[] { "TenantId", "UserId" });

        migrationBuilder.CreateIndex(
            name: "IX_AbpEntityPropertyChanges_EntityChangeId",
            table: "AbpEntityPropertyChanges",
            column: "EntityChangeId");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(
            name: "AbpEntityPropertyChanges");

        migrationBuilder.DropTable(
            name: "AbpEntityChanges");

        migrationBuilder.DropTable(
            name: "AbpEntityChangeSets");

        migrationBuilder.AlterColumn<string>(
            name: "ClaimType",
            table: "AbpUserClaims",
            nullable: true,
            oldClrType: typeof(string),
            oldMaxLength: 256,
            oldNullable: true);

        migrationBuilder.AlterColumn<string>(
            name: "UserName",
            table: "AbpUserAccounts",
            nullable: true,
            oldClrType: typeof(string),
            oldMaxLength: 32,
            oldNullable: true);

        migrationBuilder.AlterColumn<string>(
            name: "EmailAddress",
            table: "AbpUserAccounts",
            nullable: true,
            oldClrType: typeof(string),
            oldMaxLength: 256,
            oldNullable: true);

        migrationBuilder.AlterColumn<string>(
            name: "ClaimType",
            table: "AbpRoleClaims",
            nullable: true,
            oldClrType: typeof(string),
            oldMaxLength: 256,
            oldNullable: true);
    }
}
